# -*- coding: utf-8 -*- 
#按照大小分割文件
 
import os

def mk_SubFile(filename, sub, buf):
    with open(f"{filename}.sub{sub}", 'wb') as fout:
        fout.write(buf)
    return sub + 1

def split_By_size(filename, size, cut_once=False):
    try:
        with open(filename, 'rb') as fin:
            buf = fin.read(size)
            sub = 1
            while len(buf) > 0 and (not cut_once or sub == 1):
                mk_SubFile(filename, sub, buf)
                if not cut_once:
                    buf = fin.read(size)
                else:
                    break
    except IOError as e:
        print(f"An error occurred: {e}")
    except Exception as e:
        print(f"An unexpected error occurred: {e}")

    print("ok")
            
 
if __name__=="__main__":
    filename = input("Input File Name:")
    size = input("Input Bytes:")
    split_By_size(filename, int(size),True)